package net.xuhf.listener;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class MessageListener {


    public static class User {
        private String name;
        private Long age;

        public User(String name, Long age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Long getAge() {
            return age;
        }

        public void setAge(Long age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User("xuhf",30L));
        users.add(new User("xuaf",30L));
        users.add(new User("xubf",20L));
        users.add(new User("xuaf",20L));

        List<User> newUsers = users.stream().sorted(Comparator.comparing(User::getName).thenComparingLong(User::getAge)).collect(Collectors.toList());
        newUsers.forEach(System.out::println);
    }

}
